package org.incubator.text;

import org.apache.commons.lang.RandomStringUtils;
import org.incubator.ConstantGenerator;
import org.incubator.Generator;
import org.incubator.numeric.MinMaxIntegerGenerator;

public class StringGenerator implements Generator<String> {
    private static final int DEFAULT_LENGTH = 8;
    private Generator<Integer> lengthGenerator;

    public StringGenerator() {
        this.length(DEFAULT_LENGTH);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public String generate() {
        final int length = lengthGenerator.generate();
        return RandomStringUtils.randomAlphanumeric(length);
    }

    /**
     * 
     * @param length
     * @return
     */
    public StringGenerator length(int length) {
        return this.length(new ConstantGenerator<Integer>(length));
    }

    /**
     * 
     * @param min
     * @param max
     * @return
     */
    public StringGenerator length(int min, int max) {
        return this.length(new MinMaxIntegerGenerator(min, max));
    }

    /**
     * 
     * @param lengthGenerator
     * @return
     */
    public StringGenerator length(Generator<Integer> lengthGenerator) {
        this.lengthGenerator = lengthGenerator;
        return this;
    }

}
